package com.ruoyi.web.controller.community.service;

import java.util.List;

import com.ruoyi.community.domain.ServiceQuestionType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.ServiceQuestions;
import com.ruoyi.community.service.IServiceQuestionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区Controller
 * 
 * @author 袁现程
 * @date 2021-08-01
 */
@RestController
@RequestMapping("/community/service/questions")
public class ServiceQuestionsController extends BaseController
{
    @Autowired
    private IServiceQuestionsService serviceQuestionsService;

    /**
     * 查询问题列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ServiceQuestions serviceQuestions)
    {
        startPage();
        List<ServiceQuestions> list = serviceQuestionsService.selectServiceQuestionsList(serviceQuestions);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @Log(title = "社区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServiceQuestions serviceQuestions)
    {
        List<ServiceQuestions> list = serviceQuestionsService.selectServiceQuestionsList(serviceQuestions);
        ExcelUtil<ServiceQuestions> util = new ExcelUtil<ServiceQuestions>(ServiceQuestions.class);
        return util.exportExcel(list, "社区数据");
    }

    /**
     * 获取问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:community:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(serviceQuestionsService.selectServiceQuestionsById(id));
    }

    /**
     * 新增问题
     */
    @Log(title = "社区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceQuestions serviceQuestions)
    {
        return toAjax(serviceQuestionsService.insertServiceQuestions(serviceQuestions));
    }

    /**
     * 修改问题
     */
    @Log(title = "社区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceQuestions serviceQuestions)
    {
        return toAjax(serviceQuestionsService.updateServiceQuestions(serviceQuestions));
    }

    /**
     * 删除问题
     */
    @Log(title = "社区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceQuestionsService.deleteServiceQuestionsByIds(ids));
    }

    @GetMapping("/type")
    public AjaxResult getQuestionType() {
        List<ServiceQuestionType> result = serviceQuestionsService.getQuestionType();
        return AjaxResult.success("查询成功！", result);
    }

    @Log(title = "社区", businessType = BusinessType.INSERT)
    @PostMapping("/type")
    public AjaxResult addQuestionType(@RequestBody ServiceQuestionType serviceQuestionType)
    {
        return toAjax(serviceQuestionsService.insertQuestionType(serviceQuestionType));
    }

    /**
     * 查询申请问题列表
     */
    @GetMapping("/apply/list")
    public TableDataInfo listApply(ServiceQuestions serviceQuestions)
    {
        startPage();
        List<ServiceQuestions> list = serviceQuestionsService.selectApplyQuestionsList(serviceQuestions);
        return getDataTable(list);
    }
}
